package com.example.androidproject.movie.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.androidproject.R;
import com.example.androidproject.movie.bean.ResultBeanData;

import java.util.ArrayList;

public class MovieBodyAdapter extends BaseAdapter {
    private final ArrayList<ResultBeanData.DataBean> data;
    private final Context mContext;

    public MovieBodyAdapter(Context mContext, ArrayList<ResultBeanData.DataBean> data) {
        this.mContext = mContext;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.movie_body_item, null);
            viewHolder = new ViewHolder();
            viewHolder.imageView = convertView.findViewById(R.id.iv_movie_body);
            viewHolder.textView = convertView.findViewById(R.id.tv_movie_body);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        Glide.with(mContext).load(data.get(position).getSrc()).into(viewHolder.imageView);
        viewHolder.textView.setText(data.get(position).getName());
        return convertView;
    }

    static class ViewHolder {
        ImageView imageView;
        TextView textView;
    }
}
